package fun.flyee.android.pengshan.acts;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;


import butterknife.BindView;
import butterknife.OnClick;
import fun.flyee.pengshan.social.R;
import fun.flyee.android.pengshan.utils.Logger;
import fun.flyee.android.pengshan.widgets.Tips;

public abstract class BaseMapActivity extends BaseActivity
//        implements AMapLocationListener, AMap.OnMapLoadedListener
{

    @BindView(R.id.title_view)
    public TextView titleView;
//    @BindView(R.id.map_view)
//    public MapView mapView;
//
//    protected AMap map;
//    public AMapLocationClient mLocationClient;
//    protected LatLng devicePoistion;
//    protected LatLng currentPoistion;
//    protected String currentAddress;
//    protected Marker currentMarker;
//    protected MarkerOptions markerOption;

    @Override
    protected void onCreate(Bundle saveIntentBundle) {
        super.onCreate(saveIntentBundle);
        titleView.setText(getActionTitle());
//        mapView.onCreate(saveIntentBundle);
//        map = mapView.getMap();
//        map.getUiSettings().setZoomControlsEnabled(false);
//        map.setOnMapLoadedListener(this);
    }

//    @Override
//    public void onMapLoaded() {
//        onMapReady();
//    }

    protected void startLocation() {
//        mLocationClient = new AMapLocationClient(getApplicationContext());
//        mLocationClient.setLocationListener(this);
//        AMapLocationClientOption locationOption = new AMapLocationClientOption();
//        locationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Battery_Saving);
//        locationOption.setOnceLocation(true);
//        locationOption.setNeedAddress(true);
//        locationOption.setHttpTimeOut(10000);
//        mLocationClient.setLocationOption(locationOption);
//        mLocationClient.startLocation();
    }

//    @Override
//    public void onLocationChanged(AMapLocation location) {
//        if (location.getErrorCode() == 0) {
//            devicePoistion = new LatLng(location.getLatitude(), location.getLongitude());
//            if(needCurrentLocation()) {
//                currentAddress = location.getAddress();
//                lookAt(location.getLatitude(), location.getLongitude());
//            }
//            onFoundLocation();
//        } else {
//            Logger.e("AmapError", "location Error, ErrCode:"
//                    + location.getErrorCode() + ", errInfo:"
//                    + location.getErrorInfo());
//            Tips.toast("错误[" + location.getErrorCode() + "]: " + location.getErrorInfo());
//        }
//    }

    protected void onFoundLocation(){

    }

//    protected void lookAt(double lat, double lng) {
//        currentPoistion = new LatLng(lat, lng);
//        CameraUpdate mCameraUpdate = CameraUpdateFactory.newCameraPosition(new CameraPosition(currentPoistion, 16, 0, 0));
//        map.moveCamera(mCameraUpdate);
//    }

//    protected void showMarker(double lat, double lng) {
//        LatLng geo = new LatLng(lat, lng);
//        markerOption = new MarkerOptions();
//        markerOption.position(geo);
//        markerOption.draggable(false);//设置Marker可拖动
//        markerOption.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
//                .decodeResource(getResources(), R.mipmap.ic_loc_red)));
//        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
//        markerOption.setFlat(true);//设置marker平贴地图效果
//        currentMarker = map.addMarker(markerOption);
//    }

//    protected void showFlag(double lat, double lng) {
//        LatLng geo = new LatLng(lat, lng);
//        markerOption = new MarkerOptions();
//        markerOption.position(geo);
//        markerOption.draggable(false);//设置Marker可拖动
//        markerOption.icon(BitmapDescriptorFactory.fromView(View.inflate(this, R.layout.point_view, null)));
//        // 将Marker设置为贴地显示，可以双指下拉地图查看效果
//        markerOption.setFlat(true);//设置marker平贴地图效果
//        currentMarker = map.addMarker(markerOption);
//    }

    protected void removeMarker() {
//        if (currentMarker != null) {
//            currentMarker.remove();
//        }
    }

    @OnClick(R.id.back_btn)
    public void onBackClick(View v) {
        finish();
    }

    @Override
    public void onDestroy() {
//        if (mapView != null) {
//            mapView.onDestroy();
//        }
//        if (mLocationClient != null) {
//            mLocationClient.onDestroy();
//        }
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
//        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
//        mapView.onPause();
//        if (mLocationClient != null) {
//            mLocationClient.stopLocation();
//        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
//        mapView.onSaveInstanceState(outState);
    }

    protected abstract String getActionTitle();

    protected abstract boolean needCurrentLocation();

    protected abstract void onMapReady();
}
